# gmssl paths
LIBDIR = /opt/gmssl/lib
INCDIR = /opt/gmssl/include

# Compiler and flags
CC      = gcc
CFLAGS  = -Wall -I$(INCDIR)
LDFLAGS = -L$(LIBDIR) -Wl,-rpath,$(LIBDIR)
LIBS    = $(LIBDIR)/libcrypto.a -lpthread -ldl

# Target and source files
TARGETS = generate_launch_blob csv-measure
generate_launch_blob_SRCS = generate_launch_blob.c cal_vm_digest.c  crypto.c ovmf_hash_table.c  utils.c
csv-measure_SRCS = cal_vm_digest_main.c cal_vm_digest.c crypto.c utils.c ovmf_hash_table.c
OBJS   = $(SRCS:.c=.o)

define generate_objs
$(1)_OBJS = $$(patsubst %.c,%.o,$$($(1)_SRCS))
endef

$(foreach target,$(TARGETS),$(eval $(call generate_objs,$(target))))

ALL_OBJS = $(foreach target,$(TARGETS),$($(target)_OBJS))

.PHONY: all clean

all:$(TARGETS)

generate_launch_blob:$(generate_launch_blob_SRCS)
	$(CC) $(CFLAGS) -o generate_launch_blob $(generate_launch_blob_SRCS) $(LDFLAGS) $(LIBS)

csv-measure:$(csv-measure_SRCS)
	$(CC) $(CFLAGS) -o csv-measure $(csv-measure_SRCS) $(LDFLAGS) $(LIBS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f $(ALL_OBJS) $(TARGETS)

